package mysql

import (
	"gorm.io/gorm"
	"log"
)

type Order struct {
	gorm.Model
	UserId  int64  `gorm:"type:int;not null;" json:"userId"`
	GoodsId int64  `gorm:"type:int; not null;" json:"goodsId"`
	Status  int64  `gorm:"type:int;not null;default:0;" json:"status"`
	Num     int64  `gorm:"type:int;not null;" json:"num"`
	OrderId string `gorm:"type:char(36);not null;" json:"orderId"`
}

func (o *Order) CreateOrderByUserIdAndGoodsId() error {
	err := DB.Create(&o).Error
	if err != nil {
		return err
	}
	return nil
}
func (o *Order) GetOrderStatus(orderId string) bool {
	err := DB.Where("order_id=?", orderId).Limit(1).Find(&o).Error
	if err != nil {
		log.Println(err)
		return false
	}
	return true
}
func (o *Order) UpdateOrderStatus(orderId string, status int) bool {
	err := DB.Model(&o).Where("order_id=?", orderId).Update("status", status).Error
	if err != nil {
		log.Println(err)
		return false
	}
	return true
}
